import request from '@/utils/request'

export interface IUserInfo {
  id: string
  _id: string
  username: string
  password: string
  phone: string
  nickname: string
  remark: string
  createdAt: string
  updatedAt: string
  isAdmin: number
  permissions: string[]
}

type UserList = IBaseResponse<{
  page: number
  pageSize: number
  pageTotal: number
  rowTotal: number
  rows: IUserInfo[]
}>

export function getUserList(params: any) {
  return request<UserList>({
    url: '/api/user/list',
    method: 'GET',
    // params: {
    //   // 查询参数配置 ? 号传递的参数配置
    //   page: params.page,
    //   pageSize: params.pageSize
    // },
    params
  })
}

export function getUserInfo() {
  return request<IBaseResponse<IUserInfo>>({
    url: '/api/auth/profile',
    method: 'GET'
  })
}

// 更新用户的权限
export function updateUserPermission(id: string, permissions: string[]) {
  return request({
    url: '/api/user/edit',
    method: 'POST',
    data: {
      id,
      permissions
    }
  })
}
